﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ESHOP.DAO;
using ESHOP.Domain;
using ESHOP.UTIL;
using E_Shop.Common;
using System.Reflection;
using System.IO;
using System.Diagnostics;


namespace E_Shop
{
    public partial class CompanyPostNewBuyLead : Authentication
    {
        private DanhMucDAO _danhMucDao = new DanhMucDAO();
        private QuocGiaDAO _quocGia = new QuocGiaDAO();
        private SANPHAM _sanpham = new SANPHAM();
        private BUY _buy = new BUY();
        private BuyLeadDAO _buyleadDao = new BuyLeadDAO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDuLieu();
            }
        }

        private void LoadDuLieu()
        {
            CommonFunc.BindDropDownList(ddlcategory, _danhMucDao.GetList(), "TENDM", "ID", true);
            CommonFunc.BindDropDownList(dllregion, _quocGia.GetList(), "TENQUOCGIA", "ID", true);
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                _buy.MACONGTY = Acount.MACT;

                Control myControl1 = FindControl("choseimage");
                string savePath = Server.MapPath("~/Images/Product/" + fuImage.FileName);
                if (fuImage.HasFile)
                {
                    String fileName = fuImage.FileName;
                    fuImage.SaveAs(savePath);
                }
                _buy.HINHANH = fuImage.FileName;
                _buy.ID = DateTime.Now.ToString("ddmmyyhhss");
                _buy.ISHOW = false;
                _buy.KEYWORD = txtKeyword.Text.Trim();
                _buy.MAQUOCGIA = dllregion.SelectedValue;
                _buy.MOTA = txtmota.Text.Trim();
                _buy.MADM = ddlcategory.SelectedValue;
                _buy.SUBJECT = txtSubject.Text.Trim();
              
                _buy.NGAYDANG = DateTime.Now;
                if (_buyleadDao.AddNewBuyLead(_buy) == 1)
                {
                    ShowInfor("Add buying lead success");
                }
                else
                {
                    ShowError("Add buying lead fail!");
                }
                txtKeyword.Text = "";
                txtmota.Text = "";
                txtSubject.Text = "";
                //Response.Redirect("CompanyPostProductSucess.aspx");
            }
            catch {
                return;
            }
        }
    }
}